go to previous page   go to home page   go to next page

Answer:

slide = new JSlider( JSlider.HORIZONTAL, 0, 100, 79 );
slide.setMajorTickSpacing( 10);
slide.setMinorTickSpacing(  5);


setPaintTicks and setPaintLabels

Tick marks and their labels are turned on or off using these methods:

setPaintTicks ( boolean state )
setPaintLabels( boolean state )

Sometimes you want the knob of a slider to stop only at the tick marks so that the value of the slider is an integer multiple of the minor tick spacing. Use this method:

setSnapToTicks( boolean state )

QUESTION 5:

Horizontal Slider

Ask that ticks and labels be displayed as in the picture and that the knob snap to the ticks.

slide = new JSlider( JSlider.HORIZONTAL, 0, 100, 79 );
slide.setMajorTickSpacing( 10 );
slide.setMinorTickSpacing(  5 );
slide.setPaintTicks (  );
slide.setPaintLabels(  );
slide.setSnapToTicks(  );